package com.esunrising.esungsc.common.utils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

public final class ESUNUtil {

    private ESUNUtil(){

    }

    public static String showFileSize(Long size){
        if(size == null){
            return null;
        } else if(size <=0){
            return size.toString();
        }else if(size < 1024L){
            return String.format("%.1f", size.doubleValue())+" B";
        } else if (size < 1024 * 1024L) {
            return String.format("%.1f", size/1024d)+" KB";
        } else if (size < 1024 * 1024 * 1024L) {
            return String.format("%.1f", size/1024d/1024d)+" MB";
        } else{
            return String.format("%.1f", size/1024d/1024d/1024d)+" GB";
        }
    }

//    public static LocalDateTime date2LocalDateTime(Date date){
//        return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
//    }

    public static LocalDateTime date2LocalDateTime(Date date) {
        if (date != null) {
            try {
                LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
//                System.out.println("LocalDateTime: " + localDateTime);
                return localDateTime;
            } catch (Exception e) {
                System.err.println("Error converting Date to LocalDateTime: " + e.getMessage());
            }
        } else {
            System.out.println("Date is null.");
           return null;
        }
       return null;
    }
}

